/*
 * cliente.c
 *
 *  Created on: 30/10/2011
 *      Author: agustin
 */

    #include <stdio.h>
    #include <stdlib.h>
    #include <unistd.h>
    #include <errno.h>
    #include <string.h>
    #include <sys/types.h>
    #include <sys/socket.h>
    #include <netinet/in.h>
    #include <arpa/inet.h>
    #include <sys/wait.h>
    #include <signal.h>
	#include "Protocolo_NIPC.h"

#define DIRECCION_IP "192.168.1.105"

typedef struct Persona {
char nombre[50];
char apellido[50];
} t_persona;

typedef t_persona *persona;

   int main(int argc, char **argv)

{
int sockfd,handshake_OK;
paquete *NIPC_Prueba;
NIPC_Prueba = (paquete *)malloc(515);
int len;
struct sockaddr_in address;
int result;
char c[1024];

while(c[0]!='Q'||c[1]!='U'||c[2]!='I'||c[3]!='T'||c[4]!=' ')
{
/* Crear un socket para el cliente */

sockfd = socket(AF_INET, SOCK_STREAM, 0) ;
memset(&address, 0, sizeof(address));
address.sin_family = AF_INET;
address.sin_addr.s_addr = inet_addr(DIRECCION_IP) ;
address.sin_port = 2727;
len = sizeof(address);

result = connect(sockfd, (struct sockaddr *)&address, len) ;

if(result == -1)
{
perror("ERROR EN LA CONEXION" );
exit(1);
}


printf("Connected.\n");

while(1){
	  handshake_OK=handshakePPD(sockfd,"1");

		if (handshake_OK)
	   {
			printf("Se hizo el handshake\n");
	   }
		else {printf("No hubo handshake\n");
		close(sockfd);}

//	send(sockfd, NIPC, sizeof(paquete), 0);
	  /* if (recv(sockfd, str, 50, 0) == -1) {
	           perror("recv");
	           exit(1);
    }
	   printf("recibi: %s\n",str);
	   recv(sockfd,str,50,0);*/
close(sockfd);
exit(0);


}
return 0;}
}
